package com.gengealogy.net.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.gengealogy.net.po.Circle;
import com.gengealogy.net.service.CircleService;

@Controller
public class CircleController {
	@Autowired
	private CircleService circleService;

	public CircleService getCircleService() {
		return circleService;
	}

	public void setCircleService(CircleService circleService) {
		this.circleService = circleService;
	}
	/**
	 * 向朋友圈页面跳转
	 */
	@RequestMapping(value = "/user/getCircle.action")
	public String getCircle(Model model, HttpSession session) {

		int user_id = (int) session.getAttribute("USER_ID");
		List<Circle> circle = circleService.findCircle(user_id);
		if (circle == null) {
			model.addAttribute("msg", "空空如也，记得上传哦！");
			return "user/user_circle";
		} else {
			model.addAttribute("user_id", user_id);
			model.addAttribute("circle", circle);
			return "user/user_circle";
		}

	}
	
	/**
	 * 向朋友圈页面跳转
	 */
	@RequestMapping(value = "/user/getAllCircle.action")
	public String getAllCircle(Model model, HttpSession session) {

		List<Circle> circle = circleService.findAllCircle();
		if (circle == null) {
			model.addAttribute("msg", "空空如也,记得上传哦！");
			return "user/alluser_circle";
		} else {
			model.addAttribute("circle", circle);
			return "user/alluser_circle";
		}

	}

	/**
	 * 向朋友圈页面添加
	 */
	@RequestMapping(value = "/addCircle.action", method = RequestMethod.GET)
	public String toAddCircle() {
		return "build/build_addCircle";
	}

	@RequestMapping(value = "/addCircle.action", method = RequestMethod.POST)
	public String addCircle(Circle circle, Model model) {
		circleService.addCircle(circle);
		return "redirect:user/getCircle.action";
	}
}
